package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.CouponTypes;
import com.fantastic.service.zjs.CouponTypesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/2 22:28
 * @description: 优惠券类型表请求控制器
 */
@RestController
@RequestMapping("/couponTypes")
public class CouponTypesControllerAdmin {

    @Resource
    private CouponTypesService couponTypesService;

    /**
     * 查询优惠券类型信息
     *
     * @param couponTypes
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listCouponTypes")
    public ResultData listCouponTypes(CouponTypes couponTypes,
                                      @RequestParam(name="page",
                                              defaultValue = "1") int pageNum,
                                      @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CouponTypes> couponTypes1 = couponTypesService.listCouponTypes(couponTypes);
        PageInfo<CouponTypes> couponTypesPageInfo = new PageInfo<>(couponTypes1);
        return new ResultData(RespStatusInfo.OK, couponTypesPageInfo);
    }

    /**
     * 查询单个优惠券类型信息
     *
     * @param couponTypeId
     * @return
     */
    @GetMapping("/getCouponTypes")
    public ResultData getCouponTypes(Integer couponTypeId) {
        return new ResultData(RespStatusInfo.OK, couponTypesService.getCouponTypes(couponTypeId));
    }

    /**
     * 添加优惠券类型信息
     *
     * @param couponTypes
     * @return
     */
    @PostMapping("/insertCouponTypes")
    public ResultData insertCouponTypes(CouponTypes couponTypes) {
        return new ResultData(RespStatusInfo.OK, couponTypesService.insertCouponTypes(couponTypes));
    }

    /**
     * 修改优惠券类型信息
     *
     * @param couponTypes
     * @return
     */
    @PostMapping("/updateCouponTypes")
    public ResultData updateCouponTypes(CouponTypes couponTypes) {
        return new ResultData(RespStatusInfo.OK, couponTypesService.updateCouponTypes(couponTypes));
    }

    /**
     * 删除优惠券类型信息
     *
     * @param couponTypeId
     * @return
     */
    @PostMapping("/deleteCouponTypes")
    public ResultData deleteCouponTypes(Integer couponTypeId) {
        return new ResultData(RespStatusInfo.OK, couponTypesService.deleteCouponTypes(couponTypeId));
    }

}
